﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;

namespace DDOS
{
    public abstract class Screen
    {
        private List<ScreenLayer> screenLayers;

        public Screen()
        {
            screenLayers = new List<ScreenLayer>();
        }

        public virtual void Update(GameTime gt)
        {
            for (int i = screenLayers.Count - 1; i >= 0; i--)
            {

                screenLayers[i].Update(gt);
                
                try
                {
                    if (screenLayers[i].HaltFurtherUpdates)
                        break;
                }
                catch (Exception e)
                {
                    break;
                }

            }
        }

        public virtual ScreenLayer GetLayer(int i)
        {
            return screenLayers[i];
        }

        public virtual void Draw()
        {
            for (int i = 0; i < screenLayers.Count; i++)
            {
                screenLayers[i].Draw();
            }
        }

        public virtual void PushLayer(ScreenLayer newLayer)
        {
            screenLayers.Add(newLayer);
        }
        public virtual void InsertLayer(ScreenLayer newLayer, int i)
        {
            screenLayers.Insert(screenLayers.Count - i,newLayer);
        }

        public virtual void PopLayer(int i)
        {
            screenLayers.RemoveAt(screenLayers.Count - i);
        }

        public virtual void RemoveLayer(ScreenLayer layer)
        {
            screenLayers.Remove(layer);
        }

        public virtual int LayerCount()
        {
            return screenLayers.Count;
        }

        public virtual void ClearLayers()
        {
            screenLayers.Clear();
        }

        public virtual void OnLoad() { }
        public virtual void OnExit() { }
    }
}